package org.smileface.designpattern.singleton;

/**
 * @description: 静态内部类方式（懒汉式）
 * @author: chujian
 * @since: 2022-02-14 09:39
 **/
public class Singleton3 {
    private Singleton3() {
    }

    private static class LazyHolder {
        // 静态内部类加载时创建对象
        private static final Singleton3 INSTANCE = new Singleton3();
    }

    public static Singleton3 getInstance() {
        // Java使用到LazyHolder时才会加载LazyHolder，加载LazyHolder才会出发对象的创建
        return LazyHolder.INSTANCE;
    }
}
